WEBVTT

00:00.810 --> 00:02.410
Hello and welcome back to our cost.

00:02.410 --> 00:06.740
So in this session we are creating random numbers with the unpaid package.

00:07.050 --> 00:13.340
And we have already learned that we can create random random numbers with the random module of the standard

00:13.350 --> 00:14.880
python library.

00:14.940 --> 00:21.210
However creating random numbers for smart umpires more flexible and provides a lot more functionality.

00:21.210 --> 00:26.820
And it's also fast so so there's actually no reason to use the random module loft space and standard

00:26.820 --> 00:31.230
library even we can use the power for the name pi random package.

00:31.230 --> 00:40.370
So now let's first import pi and then what we would do you want to create a 10 random integers between

00:40.370 --> 00:47.180
1 and 101 excluding so let's press shift tab and you can see.

00:47.270 --> 00:54.120
So random dot Rand int returns integers font lo inclusive to high exclusive.

00:54.740 --> 01:03.260
So if you want random integers between 1 and 100 including we have to type year 101 into the third parameter

01:03.620 --> 01:04.520
is the size.

01:04.520 --> 01:12.890
So how many random numbers or integers we want to create let's execute the of here.

01:12.980 --> 01:20.210
Now you can see we get 10 random integers in the range one to one hundred and if we repeat this process

01:20.420 --> 01:29.660
we should get a different 10 random in the just because it's random and that's a very helpful instrument

01:29.660 --> 01:31.230
called random seed.

01:31.370 --> 01:38.620
So random that seed creates so-called absurd or random numbers and it enables us to reproduce the other

01:38.630 --> 01:39.710
random numbers we create.

01:39.710 --> 01:46.580
So whenever you use them the same seed as ISV in brackets if you have to define a number so here it's

01:46.580 --> 01:52.230
1 2 3 but can be any number and whenever you have we had the same number and the random seed to them

01:52.250 --> 01:56.630
you create exactly the same random numbers as I do.

01:56.920 --> 02:03.310
So let's run near the center and that's repeated the process and we should get the same numbers again

02:03.400 --> 02:05.680
because we didn't change for the random seed.

02:05.890 --> 02:07.030
All right.

02:07.150 --> 02:10.200
And we can also create normally distributed numbers.

02:10.210 --> 02:15.460
I don't want to go into details of normal distribution but it's kind of a better shape probability distribution

02:15.520 --> 02:18.340
where we can determine the means or minus 5.

02:18.880 --> 02:22.450
But it's flexible and you can determine the standard deviation.

02:22.480 --> 02:25.990
So the second position is 2.

02:25.990 --> 02:30.790
So Locke stands for the mean scale stands for the standard deviation and you can also determine the

02:30.790 --> 02:31.290
size.

02:31.300 --> 02:34.890
So how many normal distribution numbers you want to get.

02:34.900 --> 02:41.800
So when we executed we had 10 normal distribution numbers with mean 5 and standard deviation 2.

02:41.830 --> 02:50.170
All right so let's create an array with numbers between 1 and 100 so called B and then we can randomly

02:50.170 --> 02:57.880
shuffle all elements here so we can mix mix all elements up and change the sorting.

02:57.940 --> 03:02.800
Now we have to print B and you can see so be it.

03:02.800 --> 03:05.770
Now we are randomly sorted are not sorted.

03:05.770 --> 03:15.450
Actually but that's the method topside and where we can start again our unsorted array and let's check

03:15.450 --> 03:18.070
the results.

03:18.160 --> 03:24.220
Now it's sorted again now and actually for whatever reason so the method sort does not provide us the

03:24.220 --> 03:28.990
option to to sort the array in an inverse order or our reverse order.

03:28.990 --> 03:34.810
So I don't know why there's no option for it but yeah it's the case but we if you want to sort our array

03:34.810 --> 03:42.070
in the reverse order there's a trick here by double colon minus one where we have the reverse order

03:42.070 --> 03:48.100
starting from hundreds till 1 and that's another method called random that's why it's so random that

03:48.100 --> 03:55.330
choice creates a random sample from a given array so we can have our array B and then we determine the

03:55.330 --> 03:56.520
size of our sample.

03:56.510 --> 04:03.220
So for example one hundred and then we can determine whether the sample is with or without replacement.

04:03.280 --> 04:04.660
So what does that mean.

04:04.660 --> 04:10.810
Whenever an element is randomly chosen so let's say 1 the next step.

04:10.850 --> 04:13.730
Again we have the chance to choose this element.

04:13.730 --> 04:19.760
And with out replacement means that you can choose one element only once.

04:19.760 --> 04:27.740
So here we have a replacement is true and we choose a randomly select the sample of 100 elements from

04:27.740 --> 04:28.740
our array B.

04:29.510 --> 04:31.040
Let's see what we get.

04:31.040 --> 04:31.300
OK.

04:31.310 --> 04:40.020
We get a hundred elements and we can then swap our new sample array B1 and they can see so we have some

04:40.020 --> 04:48.360
duplicates so we have two was chosen two times four was chosen four times and with the method unique

04:48.830 --> 04:54.070
we can choose only the unique elements that we can remove all duplicates.

04:54.070 --> 05:01.010
There you can see we have only the unique values without any duplicates and you would get the same result

05:01.020 --> 05:06.780
by transforming our array into a set and then transforming it into a list and then to our right.

05:06.770 --> 05:10.420
So we cannot immediately transform a set into an array.

05:10.530 --> 05:15.800
So first we have to make a list and we get the same result here.

05:16.110 --> 05:22.640
And now by adding the method types you can determine how many unique elements we have here.

05:22.650 --> 05:29.160
You determine the unique elements of our sample and then that size gives us them the amount of unique

05:29.160 --> 05:32.410
values or elements of it 66.

05:32.430 --> 05:41.210
So we created 100 integers with replacement and we got back 66 unique elements and the unique method

05:41.210 --> 05:42.300
is quite informative.

05:42.300 --> 05:48.360
So it has some more parameters for example a return index it goes through and return count sequence

05:48.360 --> 05:50.310
true.

05:50.310 --> 05:53.020
So by default they are set to false.

05:53.060 --> 05:54.300
Let's see what we get.

05:54.510 --> 06:01.140
So here in the first array we have our unique elements and in the second array we get the index position

06:01.140 --> 06:05.010
of the first occurrence of our unique values.

06:05.010 --> 06:09.160
So for example if we go to our array with duplicates.

06:09.300 --> 06:17.130
The first occurrences to us of course at position 0 and the first occurrence of 3 is that position in

06:17.130 --> 06:26.110
x position to that I can see here and also kind of returns as an array with return counts.

06:26.160 --> 06:33.120
We can read that to us included in our sample two times three was included in our sample one time and

06:33.120 --> 06:37.010
four was then included in our sample four times.

06:37.080 --> 06:43.080
So this is quite informative here and we can also set the replace parameter to forwards here

06:49.230 --> 06:54.660
now there is actually no surprise because our array contains 100 elements and the free randomly select

06:54.750 --> 06:57.060
100 elements without replacement.

06:57.780 --> 07:04.440
How we actually get all 100 elements so check unique elements so we get all elements from 1 to 100

07:07.140 --> 07:10.890
and we have 100 unique elements.

07:10.890 --> 07:11.210
All right.

07:11.220 --> 07:16.520
So this was a short introduction to the number random package and we learned to create random integers

07:17.160 --> 07:20.880
normal distributed numbers and how to randomly shuffle an array.

07:20.910 --> 07:26.310
And also we learned how to make a random sample of an array and there are many more things you can do

07:26.310 --> 07:27.790
with the random module.

07:28.020 --> 07:34.180
So for example that's NPR random thought.

07:34.180 --> 07:37.970
And then if you press tab there you can see how many methods.

07:38.050 --> 07:38.560
You can.

07:38.560 --> 07:43.570
You can apply here so you can have an anomalous simulation.

07:43.570 --> 07:50.950
And yes many many things you can ask the price and distribution and so on and so on.

07:50.950 --> 07:51.300
All right.

07:51.310 --> 07:57.370
So this is it for the time being so this was a short intro to random numbers and the next session we

07:57.370 --> 08:03.330
will compare the python standard library with the PI packets in terms of performance so hope to see

08:03.330 --> 08:04.900
you there and by.
